﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebTemplate.DAL.Entities;
using WebTemplate.DAL.Repositories;

namespace WebTemplate.Web.Membership
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Login_Authenticate(object sender, AuthenticateEventArgs e)
        {
            MemberReprositry repository = new MemberReprositry();
            MembersSearchCriteria searchCriteria = new MembersSearchCriteria();
            
            searchCriteria.UserID = this.uxLogin.UserName;
            searchCriteria.Password = FormsAuthentication.HashPasswordForStoringInConfigFile(this.uxLogin.Password,"SHA1");
            searchCriteria.IsActive = true;
            List<Members> lst = repository.Select(searchCriteria);
            if (lst.Count == 1)
                e.Authenticated = true;
            else
                e.Authenticated = false;
        }
    }
}